<script setup>
	import {
		ref
	} from 'vue';

	let username = ref('')
	let password = ref('')
	const checkState = ref(false)

	uni.$on('upadateCheckState', function(data) {
		checkState.value = data.checkState
	})

	function page_upa() {
		uni.navigateTo({
			url: '/pages/UPA/UPA?checkState=' + checkState.value
		})
	}

	function login_sub() {
		if (checkState.value) {
			uni.reLaunch({
				url: '/pages/Home/Home'
			})
		} else {
			uni.showToast({
				title: '请先同意《用户隐私协议》',
				position: 'center'
			})
		}
	}
</script>

<template>
	<view class="login">
		<view class="title">登 录</view>
		<view class="form">
			<form @submit="login_sub()">
				<view class="row">
					<view class="left">
						<image src="../../static/images/login/login_username.png"></image>
					</view>
					<view class="right">
						<input type="text" placeholder="用户名/手机号" v-model="username" />
					</view>
				</view>
				<view class="row">
					<view class="left">
						<image src="../../static/images/login/login_password.png"></image>
					</view>
					<view class="right">
						<input password type="text" placeholder="请输入密码" v-model="password" />
					</view>
				</view>
				<view class="rowCheckbox">
					<checkbox-group>
						<checkbox :checked="checkState" @click="checkState = !checkState"></checkbox>
						<span>我已阅读并同意</span>
						<span @click="page_upa()">《用户隐私协议》</span>
					</checkbox-group>
				</view>
				<view class="rowBtn">
					<button form-type="submit">登 录</button>
				</view>
			</form>
		</view>
	</view>
</template>

<style scoped lang="scss">
	.login {
		width: 100vw;
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;

		.title {
			margin-top: 10vh;
			font-size: 10vw;
			font-weight: bold;
		}

		.form {
			width: 70vw;
			margin-top: 16vh;

			.row {
				width: 100%;
				display: flex;
				align-items: center;
				border-bottom: 1px solid #000;
				margin-top: 6vh;

				.left {
					image {
						width: 6vw;
						height: 6vw;
					}
				}

				.right {
					input {
						font-size: 5vw;
						padding-left: 2vw;
					}
				}
			}

			.rowCheckbox {
				margin-top: 2vh;
				font-size: 4vw;

				checkbox-group {
					display: flex;
					align-items: center;

					span:last-child {
						color: $uni-title-border-color;
					}
				}
			}

			.rowBtn {
				margin-top: 4vh;

				button {
					color: #ffffff;
					font-size: 5vw;
					border-radius: 6vh;
					background-color: $uni-title-border-color;
				}
			}
		}

	}
</style>